package com.wxit.algorithm.leetcode;

import com.wxit.algorithm.stack.ArraysStack;

/**
 * 用栈实现队列
 */
public class E14LeetCode232 {

    ArraysStack<Integer> s1 = new ArraysStack<>(100);
    ArraysStack<Integer> s2 = new ArraysStack<>(100);

    /**
     * 向队列尾部添加
     * @param x
     */
    public void push(int x) {
        s2.push(x);
    }

    /**
     * 从队列头移除
     * @return
     */
    public int pop() {
        if (s1.isEmpty()) {
            while (!s2.isEmpty()) {
                s1.push(s2.pop());
            }
        }
        return s1.pop();
    }

    public int peek() {
        if (s1.isEmpty()) {
            while (!s2.isEmpty()) {
                s1.push(s2.pop());
            }
        }
        return s1.peek();
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }
}
